package com.siae.controller;


import com.siae.pojo.Message;
import com.siae.pojo.vo.Result;
import com.siae.service.MessageService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/message")
@Tag(name = "MessageController",description = "消息操作")
public class MessageController {
    @Autowired
    private MessageService messageService;
    @GetMapping
    public Result<List<Message>> getAllMessages(@RequestParam(name = "userId",defaultValue = "0") Integer userId){
        return messageService.getAllMessages(userId);
    }
    @GetMapping("/count")
    public Result<Integer> getMessageCount(){
        return messageService.getMessageCount();
    }
    @GetMapping("/{id}")
    public Result<Message> getMessageById(@PathVariable("id") Integer id){
        return messageService.getMessageById(id);
    }
    @PostMapping
    public Result<Message> addMessage(@RequestBody Message message){
        return messageService.addMessage(message);
    }
    @PutMapping
    public Result<Message> updateMessage(@RequestBody Message message){
        return messageService.updateMessage(message);
    }
    @DeleteMapping("/{id}")
    public Result deleteMessage(@PathVariable("id") Integer id){
        return messageService.deleteMessage(id);
    }
    @GetMapping("/list")
    public Result deleteMessages(@RequestParam String ids){
        return messageService.deleteMessages(ids);
    }
}
